﻿package mortal.game.view.levelReward.cellrender
{
    import __AS3__.vec.*;
    import com.gengine.resource.info.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import fl.controls.*;
    import fl.data.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.game.view.levelReward.other.*;
    import mortal.game.view.levelReward.util.*;

    public class LevelRewardVipUpAllLevelsGiftCellRender extends GCellRenderer
    {
        private var _imgHuaWenLeft:GBitmap;
        private var _imgHuaWenRight:GBitmap;
        private var _imgLevelGo:GBitmap;
        private var _imgLv:GBitmap;
        private var _numberTxt:BitmapNumberText;
        private var _itemList:GTileList;
        private var _hasReceiveBtn:GLoadingButton;
        private var _receiveGiftBtn:GLoadingButton;
        private var _levelNotEnoughBtn:GLoadingButton;
        private var _rewardTakeArrow:SWFPlayer;
        private var _giftData:LevelRewardGiftDataGroup;

        public function LevelRewardVipUpAllLevelsGiftCellRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(9, 0, 662, 81, this, ImagesConst.LevelGiftBg));
            this.pushUIToDisposeVec(UIFactory.bg(505 + 16, 0, 2, 83, this, ImagesConst.VSplitLine));
            this._imgHuaWenLeft = UIFactory.bitmap(ImagesConst.levelReward_huawen, 120 - 40 + 60, 20 - 7, this);
            this._imgHuaWenRight = UIFactory.bitmap(ImagesConst.levelReward_huawen, 493 - 40 - 127 + 60, 22 - 7, this);
            this._imgHuaWenRight.scaleX = -1;
            this._imgLevelGo = UIFactory.bitmap(ImagesConst.levelReward_go, 180 - 40 + 60, 10 - 7, this);
            this._imgLv = UIFactory.bitmap(ImagesConst.levelReward_Lv, 245 - 40 + 60, 13 - 7, this);
            this._numberTxt = UIFactory.bitmapNumberText(269 - 40 + 60, 11 - 7, "GuildWarResultStarNum.png", 26, 27, -13, this);
            this._itemList = UIFactory.tileList(180 - 40 + 3, 36, 270, 70, this);
            this._itemList.rowHeight = 57;
            this._itemList.columnWidth = 45;
            this._itemList.horizontalGap = 0;
            this._itemList.verticalGap = 3;
            this._itemList.columnCount = 6;
            this._itemList.rowCount = 1;
            this._itemList.setStyle("cellRenderer", LevelRewardGiftListCellRender);
            this._itemList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._itemList.direction = ScrollBarDirection.HORIZONTAL;
            this._hasReceiveBtn = UIFactory.gLoadingButton(ResFileConst.HasTakenBtn, 505 + 47, 32, 93, 30, this);
            this._receiveGiftBtn = UIFactory.gLoadingButton(ResFileConst.ReceiveGiftBtn, 505 + 47, 32, 93, 30, this);
            this._levelNotEnoughBtn = UIFactory.gLoadingButton(ResFileConst.LevelNotEnoughBtn, 505 + 47, 32, 93, 30, this);
            this._receiveGiftBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseHandler);
            this._rewardTakeArrow = UICompomentPool.getUICompoment(SWFPlayer);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:DataProvider = null;
            super.data = param1;
            this._giftData = param1 as LevelRewardGiftDataGroup;
            if (this._giftData)
            {
                this._numberTxt.text = this._giftData.level.toString();
                this.setTitleByLevel(this._giftData.level);
                _loc_2 = this.getDataProvider();
                this._itemList.dataProvider = _loc_2;
                this._itemList.drawNow();
                this.resetBtnState();
                EffectManager.glowFilterUnReg(this._receiveGiftBtn);
                this.removeArrow();
                switch(this._giftData.receiveType)
                {
                    case LevelRewardGiftDataGroup.UnReceive:
                    {
                        this._levelNotEnoughBtn.visible = true;
                        break;
                    }
                    case LevelRewardGiftDataGroup.CanReceive:
                    {
                        this._receiveGiftBtn.visible = true;
                        this._receiveGiftBtn.mouseEnabled = true;
                        EffectManager.glowFilterReg(this._receiveGiftBtn);
                        this.addArrow();
                        break;
                    }
                    case LevelRewardGiftDataGroup.HasReceive:
                    {
                        this._hasReceiveBtn.visible = true;
                        break;
                    }
                    default:
                    {
                        break;
                        break;
                    }
                }
            }
            return;
        }// end function

        private function setTitleByLevel(param1:int) : void
        {
            var _loc_2:* = LevelRewardUtil.getLevelRect(param1);
            var _loc_3:* = Cache.instance.role.entityInfo.career;
            var _loc_4:* = "LevelTitle_" + param1;
            var _loc_5:String = "";
            if (_loc_2 != 0)
            {
                switch(_loc_2)
                {
                    case LevelRewardConst.LevelType_Junior:
                    {
                        _loc_5 = "Career_Lv_" + _loc_3;
                        break;
                    }
                    case LevelRewardConst.LevelType_Middle:
                    {
                        _loc_5 = "Career_Lan_" + _loc_3;
                        break;
                    }
                    case LevelRewardConst.LevelType_Senior:
                    {
                        _loc_5 = "Career_Zi_" + _loc_3;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return;
        }// end function

        private function showBg(param1:SWFInfo) : void
        {
            if (isDisposed)
            {
                return;
            }
            return;
        }// end function

        private function onMoveBtnMouseHandler(event:MouseEvent) : void
        {
            var e:* = event;
            GameProxy.levelReward.getLevelReward(this._giftData.level);
            if (AutoGuideCache.isGuidingLevelReward)
            {
                var closeWin:* = function () : void
            {
                GameController.signUp.view.hide();
                return;
            }// end function
            ;
                setTimeout(closeWin, 500);
                AutoGuideCache.isGuidingLevelReward = false;
            }
            return;
        }// end function

        private function flyToBackPack(event:DataEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:Object = null;
            var _loc_6:LevelRewardGiftListCellRender = null;
            var _loc_7:Point = null;
            if (isDisposed)
            {
                return;
            }
            var _loc_2:* = event.data as int;
            if (_loc_2 == this._giftData.level)
            {
                _loc_3 = this._itemList.length;
                _loc_4 = 0;
                while (_loc_4 < _loc_3)
                {
                    
                    _loc_5 = this._itemList.getItemAt(_loc_4);
                    _loc_6 = this._itemList.itemToCellRenderer(_loc_5) as LevelRewardGiftListCellRender;
                    if (_loc_6)
                    {
                        _loc_7 = _loc_6._item.localToGlobal(new Point(0, 0));
                        FlyToNavbarTool.flyToBackPack(_loc_6._item.bitmapdata, _loc_7);
                    }
                    _loc_4++;
                }
                if (!Cache.instance.signUp.hasRewardToGet())
                {
                    GameController.signUp.view.hide();
                }
            }
            return;
        }// end function

        private function getDataProvider() : DataProvider
        {
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            var _loc_1:* = this._giftData.itemGiftBagInfos;
            var _loc_2:* = new DataProvider();
            _loc_3 = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_4 = _loc_1[_loc_3].extData;
                if (this._giftData.receiveType == LevelRewardGiftDataGroup.HasReceive)
                {
                    _loc_4["enble"] = false;
                }
                else
                {
                    _loc_4["enble"] = true;
                }
                _loc_2.addItem(_loc_1[_loc_3]);
                _loc_3++;
            }
            return _loc_2;
        }// end function

        private function resetBtnState() : void
        {
            this._hasReceiveBtn.visible = false;
            this._receiveGiftBtn.visible = false;
            this._levelNotEnoughBtn.visible = false;
            this._hasReceiveBtn.mouseEnabled = false;
            this._receiveGiftBtn.mouseEnabled = false;
            this._levelNotEnoughBtn.filterEnabled = false;
            return;
        }// end function

        private function addArrow() : void
        {
            this._rewardTakeArrow.timeRate = 2;
            this._rewardTakeArrow.load("guideArrow.swf", ModelType.NormalSwf, null);
            this._rewardTakeArrow.move(this._receiveGiftBtn.x - 10, this._receiveGiftBtn.y + 10);
            this.addChild(this._rewardTakeArrow);
            return;
        }// end function

        private function removeArrow() : void
        {
            DisplayUtil.removeMe(this._rewardTakeArrow);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            EffectManager.glowFilterUnReg(this._receiveGiftBtn);
            this._imgHuaWenLeft.dispose(param1);
            this._imgHuaWenRight.dispose(param1);
            this._imgLevelGo.dispose(param1);
            this._imgLv.dispose(param1);
            this._numberTxt.dispose(param1);
            this._hasReceiveBtn.dispose(param1);
            this._receiveGiftBtn.dispose(param1);
            this._levelNotEnoughBtn.dispose(param1);
            this._itemList.dispose(param1);
            this._rewardTakeArrow.dispose();
            this._imgHuaWenLeft = null;
            this._imgHuaWenRight = null;
            this._imgLevelGo = null;
            this._imgLv = null;
            this._numberTxt = null;
            this._itemList = null;
            this._hasReceiveBtn = null;
            this._receiveGiftBtn = null;
            this._levelNotEnoughBtn = null;
            this._rewardTakeArrow = null;
            this._giftData = null;
            return;
        }// end function

    }
}
